﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace PSE.Deployment.SetupBase.Configuration
{
    [Serializable]
    public class RegistryKey
    {
        [XmlAttribute()]
        public string Name { get; set; }
        [XmlAttribute()]
        public string Title { get; set; }
        [XmlAttribute()]
        public string Description { get; set; }
        public List<RegistryValue> Values { get; set; }

        public RegistryKey()
        {
            Values = new List<RegistryValue>();
        }

        public bool HasAnyVisibleValue
        {
            get
            {
                bool hasAtLeastOneVisibleValue = false;

                if (Values != null && Values.Count > 0)
                {
                    foreach (RegistryValue value in Values)
                    {
                        if (value.IsVisible)
                        {
                            hasAtLeastOneVisibleValue = true;
                            break;
                        }
                    }
                }

                return hasAtLeastOneVisibleValue;
            }
        }

        public bool HasAnyPropertyChanged
        {
            get
            {
                bool hasAtLeastOnePropertyChanged = false;

                if (Values != null && Values.Count > 0)
                {
                    foreach (RegistryValue value in Values)
                    {
                        if (value.HasChanges)
                        {
                            hasAtLeastOnePropertyChanged = true;
                            break;
                        }
                    }
                }

                return hasAtLeastOnePropertyChanged;
            }
            set 
            {
                if (Values != null && Values.Count > 0)
                {
                    foreach (RegistryValue v in Values)
                    {
                        v.HasChanges = false;                        
                    }
                }
            }
        }
    }
}
